﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Drawing;

using dotnetCHARTING;
using EZCRS.HCMS.Bll;
using EZCRS.HCMS.Bll.revenue;
using EZCRS.HCMS.Web;

namespace EZCRS.HCMS.Web.manage.AIR
{
    public partial class rev_report : ManageBase
    {

        private RMS _rms = new RMS();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CheckModule(76);

                if (base.BasHotelId == 0)
                    Response.Write(CFun.AlertMeg(Resources.Site.MustHotel, "back", ""));

                int iYear1 = DateTime.Now.Year - 5;

                for (int i = iYear1; i <= DateTime.Now.Year; i++)
                {
                    ddlYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
                }

                ddlYear.SelectedIndex = ddlYear.Items.Count - 1;
            }

        }

        /// <summary>
        /// 生成报表
        /// </summary>
        /// <param name="ADR"></param>
        /// <param name="OCC"></param>
        /// <param name="RevPAR"></param>
        private void CreateReport(out SeriesCollection ADR, out SeriesCollection OCC, out SeriesCollection RevPAR)
        {
            //ADR

            ADR = new SeriesCollection();
            OCC = new SeriesCollection();
            RevPAR = new SeriesCollection();

            Series serADR = new Series();
            Series serOCC = new Series();
            Series serPAR = new Series();

            serADR.Name = "ADR";
            serOCC.Name = "OCC %";
            serPAR.Name = "RevPAR";

            

            for (int i = 1; i <= 12; i++)
            {

                _rms.Execute(base.BasPropertyId, Convert.ToInt16(ddlYear.SelectedValue), i);

                Element elADR = new Element();

                elADR.Name = i.ToString();

                elADR.YValue = _rms.ADR;

                elADR.ShowValue = true;

                serADR.Elements.Add(elADR);

                
                ADR.Add(serADR);


                Element elOCC = new Element();

                elOCC.Name = i.ToString();

                elOCC.YValue = _rms.OCC;
                
                elOCC.ShowValue = true;

                serOCC.Elements.Add(elOCC);

                OCC.Add(serOCC);


                Element elPAR = new Element();

                elPAR.Name = i.ToString();

                elPAR.YValue = _rms.RevPAR;
                elPAR.ShowValue = true;

                serPAR.Elements.Add(elPAR);

                RevPAR.Add(serPAR);


            }


            ADR[0].DefaultElement.Color = Color.FromArgb(49, 255, 49);
            ADR[0].Type = SeriesType.Column;
            
            OCC[0].DefaultElement.Color = Color.FromArgb(255, 255, 49);
            OCC[0].Type = SeriesType.Column;

            RevPAR[0].DefaultElement.Color = Color.FromArgb(49, 255, 255);
            RevPAR[0].Type = SeriesType.Spline;   

        }



        protected void btnShow_Click(object sender, EventArgs e)
        {

            SeriesCollection scADR = new SeriesCollection();
            SeriesCollection scOCC = new SeriesCollection();
            SeriesCollection scPAR = new SeriesCollection();

            CreateReport(out scADR, out scOCC, out scPAR);

            //ADR
            chartADR.Title = "ADR Report";

            chartADR.YAxis.Scale = Scale.Normal;

            chartADR.XAxis.Label.Text = "Month";

            chartADR.YAxis.Label.Text = DateTime.Now.Year.ToString();

            chartADR.TempDirectory = "../../temp";

            chartADR.Width = 700;
            chartADR.Height = 300;

            chartADR.SeriesCollection.Add(scADR);

            //OCC
            chartOCC.Title = "OCC Report";
            chartOCC.Depth = 15;
            chartOCC.Use3D = true;
            chartOCC.XAxis.ClusterColumns = false;

            chartOCC.DefaultSeries.DefaultElement.Transparency = 20;

            chartOCC.DefaultSeries.Line.Width = 3;

            chartOCC.YAxis.Scale = Scale.Normal;

            chartOCC.XAxis.Label.Text = "Month";

            chartOCC.YAxis.Label.Text = DateTime.Now.Year.ToString();

            chartOCC.TempDirectory = "../../temp";

            chartOCC.Width = 700;
            chartOCC.Height = 300;

            chartOCC.SeriesCollection.Add(scOCC);

            //Rev
            chartRevPAR.Title = "RevPAR Report";
            chartRevPAR.Depth = 15;
            chartRevPAR.Use3D = true;
            chartRevPAR.XAxis.ClusterColumns = false;

            chartRevPAR.DefaultSeries.DefaultElement.Transparency = 20;
            chartRevPAR.DefaultSeries.Line.Width = 3;
            chartRevPAR.YAxis.Scale = Scale.Normal;
            chartRevPAR.XAxis.Label.Text = "Month";
            chartRevPAR.YAxis.Label.Text = DateTime.Now.Year.ToString();

            chartRevPAR.TempDirectory = "../../temp";

            chartRevPAR.Width = 700;
            chartRevPAR.Height = 300;

            chartRevPAR.SeriesCollection.Add(scPAR);

        }
    }
}
